<template>
    <div class="order-item-btn">
        <div class="left">
            <div class="left-content" v-if="itemData.orderStatus === 1">
                <img class="icon-time" src="@/assets/img/order/icon-time.png" alt="">
                <span class="time">{{ remainingTime }}分</span>
                <span class="msg">{{ itemData.summary }}</span>
            </div>
        </div>

        <div class="right">
            <button v-if="itemData.orderStatus === 1" class="btn connect">联系房东</button>
            <button v-if="itemData.orderStatus === 1" class="btn pay">去支付</button>

            <button v-if="itemData.orderStatus === 5" class="btn delete">删除</button>
            <button v-if="itemData.orderStatus === 5" class="btn order">
                再次预定
            </button>
        </div>
    </div>
</template>


<script setup>
import { onMounted, ref } from 'vue'

const props = defineProps({
    itemData: {
        type: Object,
        default: () => ({})
    }
})

const remainingTime = ref(0);
const timer = ref(null);
let counter = 1

// 开始倒计时,并且要将数字转化为分秒
const startCountDown = () => {
    timer.value = setInterval(() => {
        remainingTime.value = parseInt((props.itemData.countdown - counter) / 60);
        counter++;
        if (remainingTime.value <= 0) {
            clearInterval(timer.value);
            return;
        }
    }, 1000)
}
// 挂载方法
onMounted(() => {
    startCountDown()
})


</script>


<style lang="less" scoped>
.order-item-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    height: 60px;

    .left {
        .left-content {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            font-size: 11px;

            .icon-time {
                width: 11px;
                height: 11px;
                margin-right: 3px;
            }

            .time {
                color: var(--primary-color);
                letter-spacing: 0;
                margin-right: 1px;
            }

            .msg {
                color: #666;
                letter-spacing: 0;
                line-height: 11px;
            }
        }
    }

    .right {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;

        .btn {
            display: inline-block;
            text-align: center;
            line-height: 30px;
            margin-left: 10px;

            font-size: 14px;
            min-width: 75px;
            color: #666;
            background-color: #fff;
            border: 1px solid #e9e9e9;
            border-radius: 6px;
        }

        .pay {
            color: #fff;
            background-color: var(--primary-color);
            border: 1px solid var(--primary-color);
        }

        .order {
            color: var(--primary-color);
            background-color: #fff;
            border: 1px solid var(--primary-color);
        }
    }

}
</style>